<!--
 * @Date         : 2024-03-03 15:34:35
 * @LastEditTime : 2024-03-30 19:52:59
 * @description  : 
-->
<template>
  <div class="mask" v-if="dialogVisible"></div>
  <transition name="el-fade-in-linear">
    <div v-if="dialogVisible" class="pupoup">
      <div class="close" @click="hide">
        <el-icon size="20px" color="#652E1B"><Close /></el-icon>
      </div>
      <div class="header">确认提交</div>
      <div class="popup_content">
        <div class="tip">验证码：</div>
        <div class="code-row">
          <el-input v-model="code"></el-input>
          <div class="code">
            <el-image
              @click="onCreatedCode"
              style="width: 100%; height: 100%"
              :src="codeImg"
            ></el-image>
          </div>
        </div>
      </div>
      <div class="popup_bottom">
        <el-button color="#652E1B" @click="ok"> 确认提交 </el-button>
        <el-button style="border-color: #855c4c; color: #855c4c" @click="hide">
          取消
        </el-button>
      </div>
    </div>
  </transition>
</template>

<script setup>
import { captcha } from "@/api";

const code = ref(""); //输入的code
const codeKey = ref(""); //对应的codeKey
const dialogVisible = ref(false); //弹窗展示
const codeImg = ref(""); //弹窗展示
// 弹窗剩余
const show = async () => {
  code.value = "";
  await onCreatedCode();
  dialogVisible.value = true;
};
const ok = () => {
  if (!code.value) {
    ElNotification({
      title: "错误提示",
      message: "请输入验证码",
      type: "error",
    });
    return;
  }
  emit("codeVlue", { code: code.value, codeKey: codeKey.value });
};
// 创建验证码
const onCreatedCode = async () => {
  let res = await captcha();
  codeImg.value = res.data.captcha;
  codeKey.value = res.data.key;
};
const hide = () => {
  dialogVisible.value = false;
};
// $emit("code", code.value);
const emit = defineEmits(["codeVlue"]);

// 暴露;
defineExpose({
  show,
  hide,
});
</script>

<style lang="scss" scoped>
.pupoup {
  position: fixed;
  z-index: 1000;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 450px;
  height: 224px;
  background: #ccc;
  margin: auto;
  background-image: url("@/assets/popup-code.png");
  background-repeat: no-repeat;
  background-size: 100% 100%;
  box-sizing: border-box;
  padding: 0px 40px 40px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  overflow: hidden;
  border-radius: 12px;
  box-shadow: 5px 10px 5px #ccc;
  .close {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 25px;
    height: 25px;
    z-index: 1001;
    background: #fff2;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
  }
  .header {
    color: #fff;
    height: 50px;
    line-height: 50px;
  }
  .popup_content {
    flex: 1;
    overflow-y: auto;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    color: #855c4c;
    flex-direction: column;
    .tip {
      margin-bottom: 10px;
    }
    .code-row {
      display: flex;
      .code {
        width: 141px;
        height: 41px;
        background: #000;
        margin-left: 20px;
      }
    }
  }
  .popup_bottom {
    display: flex;
    flex-shrink: 0;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    padding: 0 20px;
  }
}
.mask {
  position: fixed;
  z-index: 999;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  height: 100%;
  // background: #000;
}
</style>
